package com.junjie.checkin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.junjie.checkin.entity.TStudentActivityHistory;
import com.junjie.checkin.response.admin.RegistrationListPageResponse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @author 洪浚杰
 * @description 活动历史记录Mapper
 * @date 2025/6/13 19:30
 */
@Mapper
public interface StudentActivityHistoryMapper extends BaseMapper<TStudentActivityHistory> {
    // 获取某个活动的参与人数
    @Select("select count(*) from t_student_activity_history where activity_id = #{activityId}")
    public Integer getActivityParticipants(Integer activityId);


    Map<Integer, Integer> getActivityParticipantsByActivityIds(List<Integer> activityIds);

    //  查询用户是否有参加某个活动
    @Select("select * from t_student_activity_history where activity_id=#{activityId} and user_id = #{userId}")
    public TStudentActivityHistory checkUserParticipated(Integer activityId, Integer userId);


    /**
     * 获取某个活动报名每个状态的人数
     * @param map
     * @return
     */
    Integer getStatusNumber(Map map);

    @Select("select u.username, u.nickname, h.create_time from t_student_activity_history as h left join t_user as u on h.user_id = u.id WHERE h.activity_id = #{id}")
    List<RegistrationListPageResponse> getRegistrationList(Integer id);

    /**
     * 批量签到
     * @param ids
     */
    void batchCheckIn(List<Long> ids,Long activityId);

    /**
     *查询多个id的记录
     * @param ids
     * @return
     */
    List<TStudentActivityHistory> getByListIds(List<Long> ids);

    /**
     * 修改状态
     * @param id
     */
    @Update("update t_student_activity_history set status = 'signIn',update_time = NOW() where user_id = #{id}")
    void updateStatus(Integer id);

    /**
     * 取消报名
     * @param id
     */
    @Update("update t_student_activity_history set status = 'cancelled',update_time = NOW() where user_id = #{id}")
    void cancelRegistration(Integer id);
}
